﻿@using Lib.core;
@using Lib.helper;

@using Bll;
@using Model;
@using Lib.model;
@using WebLogic.Model.User;
@using WebLogic.Bll.User;
@{
    Layout = null;
}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!-- header page -->
    @Html.Partial(IncludePath("header"))
</head>

<body>
    @Html.Partial(IncludePath("body_top"))
    @Html.Partial(IncludePath("manage_nav"))


    <div class="container">

        <div class="row">
            <div class="col-md-12">
                <div class="right" style="margin-bottom:20px;">
                    <a href="/admin/permission/roleedit/" class="btn btn-primary layer_win" target="_blank">添加角色</a>
                </div>
            </div>
            <div class="col-md-12">
                <div class="box">
                    @{
                        var list = ViewData["list"] as IList<RoleModel>;
                        if (ValidateHelper.IsPlumpList(list))
                        {
                            <table class="table table-responsive">
                                <thead>
                                    <tr>
                                        <td>ID</td>
                                        <td>名称</td>
                                        <td>描述</td>
                                        <td>默认</td>
                                        <td>操作</td>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach (var model in list)
                                    {
                                        <tr>
                                            <td>@(model.RoleID)</td>
                                            <td>@(model.RoleName)</td>
                                            <td>@(model.RoleDescription)</td>
                                            <td>@(model.AutoAssignRole == "true" ? "是" : "")</td>
                                            <td>
                                                <a href="/admin/permission/rolepermission/?role_id=@(model.RoleID)" target="_blank">管理权限</a>
                                                <br />
                                                <a href="/admin/permission/roleedit/?id=@(model.RoleID)" class="layer_win" target="_blank">修改角色</a>
                                                <br />
                                                <a href="javascript:;" class="delrolebtn" data-id="@(model.RoleID)" target="_blank">删除角色</a>
                                            </td>
                                        </tr>
                                    }
                                </tbody>
                            </table>
                        }
                        else
                        {
                            <div class="alert alert-success">系统未设置任何角色</div>
                        }
                    }
                </div>
            </div>
        </div>

    </div>

    <script type="text/javascript">
        $(function () {
            $('.delrolebtn').click(function () {
                if (!confirm('删除后相关联用户将失去指定权限，确定操作？')) {
                    return false;
                }
                postJson('/admin/permission/deleteroleaction/', {
                    id: $(this).attr('data-id'),
                }, function (res) {
                    if (res && res.success) {
                        alert('删除成功');
                        window.location.reload();
                    }
                    else {
                        alert(res.msg);
                    }
                });
            });
        });
    </script>

    <!-- footer page -->
    @Html.Partial(IncludePath("body_bottom"))
</body>
</html>
